//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.yang.newcustomcuilian.loader;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import com.yang.newcustomcuilian.NewCustomCuiLian;
import com.yang.newcustomcuilian.attribute.Attribute;
import com.yang.newcustomcuilian.level.Level;
import com.yang.newcustomcuilian.newapi.NewAPI;
import com.yang.newcustomcuilian.particleseffect.Wings;
import com.yang.newcustomcuilian.stone.Stone;
import com.yang.newcustomcuilian.suiteffect.SuitEffect;
import com.yang.newcustomcuilian.variable.Variable;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;

public class Loader {
    public Loader() {
    }

    public static void loadDLLs(List<String> dependDlls, Plugin p) {
        Iterator var2 = dependDlls.iterator();

        while(var2.hasNext()) {
            String s = (String)var2.next();
            loadLib(s, p);
        }

    }

    public static void loadLib(String lib, Plugin p) {
        File file = new File(p.getDataFolder(), lib);
        if (!file.exists()) {
            p.saveResource(lib, true);
        }

        System.load(file.getAbsolutePath());
    }

    public static void readCuiLianItem(Plugin p) {
        NewCustomCuiLian.customCuilianManager.ItemList.clear();
        File file1 = new File(p.getDataFolder(), "Item.yml");
        YamlConfiguration config1 = YamlConfiguration.loadConfiguration(file1);
        if (file1.exists()) {
            Iterator var3 = config1.getStringList("arms").iterator();

            String str5;
            while(var3.hasNext()) {
                str5 = (String)var3.next();
                NewCustomCuiLian.arms.add(Material.getMaterial(str5));
            }

            var3 = config1.getStringList("helmet").iterator();

            while(var3.hasNext()) {
                str5 = (String)var3.next();
                NewCustomCuiLian.helmet.add(Material.getMaterial(str5));
            }

            var3 = config1.getStringList("chestplate").iterator();

            while(var3.hasNext()) {
                str5 = (String)var3.next();
                NewCustomCuiLian.chestplate.add(Material.getMaterial(str5));
            }

            var3 = config1.getStringList("leggings").iterator();

            while(var3.hasNext()) {
                str5 = (String)var3.next();
                NewCustomCuiLian.leggings.add(Material.getMaterial(str5));
            }

            var3 = config1.getStringList("boots").iterator();

            while(var3.hasNext()) {
                str5 = (String)var3.next();
                NewCustomCuiLian.boots.add(Material.getMaterial(str5));
            }
            NewCustomCuiLian.customCuilianManager.ItemList.addAll(NewCustomCuiLian.arms);
            NewCustomCuiLian.customCuilianManager.ItemList.addAll(NewCustomCuiLian.helmet);
            NewCustomCuiLian.customCuilianManager.ItemList.addAll(NewCustomCuiLian.chestplate);
            NewCustomCuiLian.customCuilianManager.ItemList.addAll(NewCustomCuiLian.leggings);
            NewCustomCuiLian.customCuilianManager.ItemList.addAll(NewCustomCuiLian.boots);
        } else {
            p.saveResource("Item.yml", true);
            readCuiLianItem(p);
        }

        NewCustomCuiLian.powerArms.clear();
        NewCustomCuiLian.powerHelmet.clear();
        NewCustomCuiLian.powerChestplate.clear();
        NewCustomCuiLian.powerLeggings.clear();
        NewCustomCuiLian.powerBoots.clear();
        File file2 = new File(p.getDataFolder(), "power.yml");
        YamlConfiguration config2 = YamlConfiguration.loadConfiguration(file2);
        if (file2.exists()) {
            NewCustomCuiLian.powerArms = config2.getStringList("arms");
            NewCustomCuiLian.powerHelmet = config2.getStringList("helmet");
            NewCustomCuiLian.powerChestplate = config2.getStringList("chestplate");
            NewCustomCuiLian.powerLeggings = config2.getStringList("leggings");
            NewCustomCuiLian.powerBoots = config2.getStringList("boots");
        } else {
            p.saveResource("power.yml", true);
            readCuiLianItem(p);
        }

        NewCustomCuiLian.localArms.clear();
        NewCustomCuiLian.localHelmet.clear();
        NewCustomCuiLian.localChestplate.clear();
        NewCustomCuiLian.localLeggings.clear();
        NewCustomCuiLian.localBoots.clear();
        File file3 = new File(p.getDataFolder(), "local.yml");
        YamlConfiguration config3 = YamlConfiguration.loadConfiguration(file3);
        if (file3.exists()) {
            NewCustomCuiLian.localArms = config3.getStringList("arms");
            NewCustomCuiLian.localHelmet = config3.getStringList("helmet");
            NewCustomCuiLian.localChestplate = config3.getStringList("chestplate");
            NewCustomCuiLian.localLeggings = config3.getStringList("leggings");
            NewCustomCuiLian.localBoots = config3.getStringList("boots");
        } else {
            p.saveResource("local.yml", true);
            readCuiLianItem(p);
        }
    }

    public static void readYml(Plugin p) {
        NewCustomCuiLian.customCuilianManager.customCuilianLevelList.clear();
        File file0 = new File(p.getDataFolder(), "config.yml");
        YamlConfiguration config0 = YamlConfiguration.loadConfiguration(file0);
        if (file0.exists()) {
            NewCustomCuiLian.usingDefaultPower = config0.getBoolean("UsingDefaultPower");
        } else {
            p.saveResource("config.yml", true);
            readYml(p);
        }

        File file2 = new File(p.getDataFolder(), "cuilian" + NewAPI.getFileVersion() + ".yml");
        YamlConfiguration config2 = YamlConfiguration.loadConfiguration(file2);
        if (file2.exists()) {
            int i;
            for(i = 0; config2.getString(i + ".lore") != null; ++i) {
                Attribute a = E(config2, i);
                boolean notice = config2.getBoolean(i + ".Notice");
                List<String> cuilianLore = config2.getStringList(i + ".lore");
                String addLore = "";
                ItemStack item = null;
                if (config2.getBoolean(i + ".quenchingProtectRune")) {
                    String DisplayName = config2.getString(i + ".quenchingProtectRuneItem.item.DisplayName");
                    List<String> lore = config2.getStringList(i + ".quenchingProtectRuneItem.item.Lore");
                    Material itemtype = Material.getMaterial(config2.getString(i + ".quenchingProtectRuneItem.item.Type"));
                    addLore = config2.getString(i + ".quenchingProtectRuneItem.item.addLore");
                    item = new ItemStack(itemtype);
                    ItemMeta im = item.getItemMeta();
                    im.setDisplayName(DisplayName);
                    im.setLore(lore);
                    item.setItemMeta(im);
                }

                SuitEffect se = NewCustomCuiLian.customCuilianManager.NULLSuitEffect;
                if (config2.getBoolean(i + ".suitEffect")) {
                    int tzhp = config2.getInt(i + ".suitEffectHP");
                    List<String> suitEffects = config2.getStringList(i + ".suitEffectSet");
                    se = new SuitEffect(suitEffects, tzhp);
                }

                int[][] effectlist = new int[1][1];
                double zj = 0.0D;
                double yj = 0.0D;
                double distanceAdd = 0.0D;
                String filename = config2.getString(i + ".suitEffectWings");
                File file3 = new File(p.getDataFolder(), filename + ".txt");
                if (file3.exists()) {
                    try {
                        BufferedReader in = new BufferedReader(new FileReader(file3));
                        Throwable var25 = null;

                        try {
                            String line = in.readLine();
                            zj = Double.parseDouble(line.replace("z+: ", ""));
                            line = in.readLine();
                            yj = Double.parseDouble(line.replace("y+: ", ""));
                            line = in.readLine();
                            int Long = Integer.parseInt(line.replace("long: ", ""));
                            line = in.readLine();
                            int height = Integer.parseInt(line.replace("height: ", ""));
                            line = in.readLine();
                            distanceAdd = Double.parseDouble(line.replace("distanceAdd: ", ""));
                            effectlist = new int[height][Long];

                            for(int j = 0; j < height; ++j) {
                                line = in.readLine();
                                if (line != null) {
                                    String[] temp = line.split(", ");

                                    for(int z = 0; z < Long; ++z) {
                                        effectlist[j][z] = Integer.parseInt(temp[z]);
                                    }
                                }
                            }
                        } catch (Throwable var40) {
                            var25 = var40;
                            throw var40;
                        } finally {
                            if (in != null) {
                                if (var25 != null) {
                                    try {
                                        in.close();
                                    } catch (Throwable var39) {
                                        var25.addSuppressed(var39);
                                    }
                                } else {
                                    in.close();
                                }
                            }

                        }
                    } catch (IOException var42) {
                    }
                } else {
                    p.saveResource(filename + ".txt", true);
                    readYml(p);
                }

                Level level = new Level(i, cuilianLore, addLore, notice, config2.getBoolean(i + ".suitEffect"), a, se, item, config2.getBoolean(i + ".quenchingProtectRune"), new Wings(effectlist, zj, yj, distanceAdd), config2.getInt(i + ".moveLevelUse"));
                NewCustomCuiLian.customCuilianManager.customCuilianLevelList.add(level);
                Iterator var47 = NewCustomCuiLian.customCuilianManager.customCuilianStoneList.iterator();

                while(var47.hasNext()) {
                    Stone stone = (Stone)var47.next();
                    String StoneId = stone.id;
                    HashMap<Level, Double> LevelProbability = stone.levelProbability;
                    if (config2.get(i + "." + StoneId) != null) {
                        double probability = config2.getDouble(i + "." + StoneId);
                        LevelProbability.put(level, probability);
                    } else {
                        LevelProbability.put(level, 100.0D);
                    }
                }
            }

            NewCustomCuiLian.Max = i - 1;
        } else {
            p.saveResource("cuilian" + NewAPI.getFileVersion() + ".yml", true);
            readYml(p);
        }

    }

    public static void readItem(Plugin p) {
        NewCustomCuiLian.customCuilianManager.customCuilianStoneList.clear();
        File file1 = new File(p.getDataFolder(), "cuilianStone" + NewAPI.getFileVersion() + ".yml");
        YamlConfiguration config1 = YamlConfiguration.loadConfiguration(file1);
        if (!file1.exists()) {
            p.saveResource("cuilianStone" + NewAPI.getFileVersion() + ".yml", true);
            readItem(p);
        } else {
            for(int i = 0; config1.get(i + ".DisplayName") != null; ++i) {
                String name = config1.getString(i + ".DisplayName");
                String stoneId = config1.getString(i + ".Id");
                List<String> lore = config1.getStringList(i + ".Lore");
                int riseLevel = config1.getInt(i + ".riseLevel");
                Material itemtype = Material.getMaterial(config1.getString(i + ".Type"));
                List<Integer> dropLevel = config1.getIntegerList(i + ".dropLevel");
                ItemStack item = new ItemStack(itemtype);
                ItemMeta id = item.getItemMeta();
                id.addEnchant(Enchantment.OXYGEN, 1, true);
                id.setDisplayName(name);
                id.setLore(lore);
                item.setItemMeta(id);
                NewCustomCuiLian.customCuilianManager.customCuilianStoneList.add(new Stone(item, stoneId, dropLevel, riseLevel));
            }

        }
    }

    public static Attribute E(YamlConfiguration config1, int i) {
        HashMap<String, Integer> damageMap = new HashMap();
        damageMap.putAll(NewAPI.getHashMap("arms", config1, i, "damage"));
        damageMap.putAll(NewAPI.getHashMap("helmet", config1, i, "damage"));
        damageMap.putAll(NewAPI.getHashMap("chestplate", config1, i, "damage"));
        damageMap.putAll(NewAPI.getHashMap("leggings", config1, i, "damage"));
        damageMap.putAll(NewAPI.getHashMap("boots", config1, i, "damage"));
        HashMap<String, Integer> bloodSuckMap = new HashMap();
        bloodSuckMap.putAll(NewAPI.getHashMap("arms", config1, i, "bloodSuck"));
        bloodSuckMap.putAll(NewAPI.getHashMap("helmet", config1, i, "bloodSuck"));
        bloodSuckMap.putAll(NewAPI.getHashMap("chestplate", config1, i, "bloodSuck"));
        bloodSuckMap.putAll(NewAPI.getHashMap("leggings", config1, i, "bloodSuck"));
        bloodSuckMap.putAll(NewAPI.getHashMap("boots", config1, i, "bloodSuck"));
        HashMap<String, Integer> jumpMap = new HashMap();
        jumpMap.putAll(NewAPI.getHashMap("arms", config1, i, "jump"));
        jumpMap.putAll(NewAPI.getHashMap("helmet", config1, i, "jump"));
        jumpMap.putAll(NewAPI.getHashMap("chestplate", config1, i, "jump"));
        jumpMap.putAll(NewAPI.getHashMap("leggings", config1, i, "jump"));
        jumpMap.putAll(NewAPI.getHashMap("boots", config1, i, "jump"));
        HashMap<String, Integer> defenseMap = new HashMap();
        defenseMap.putAll(NewAPI.getHashMap("arms", config1, i, "defense"));
        defenseMap.putAll(NewAPI.getHashMap("helmet", config1, i, "defense"));
        defenseMap.putAll(NewAPI.getHashMap("chestplate", config1, i, "defense"));
        defenseMap.putAll(NewAPI.getHashMap("leggings", config1, i, "defense"));
        defenseMap.putAll(NewAPI.getHashMap("boots", config1, i, "defense"));
        HashMap<String, Integer> reboundDamageMap = new HashMap();
        reboundDamageMap.putAll(NewAPI.getHashMap("arms", config1, i, "reboundDamage"));
        reboundDamageMap.putAll(NewAPI.getHashMap("helmet", config1, i, "reboundDamage"));
        reboundDamageMap.putAll(NewAPI.getHashMap("chestplate", config1, i, "reboundDamage"));
        reboundDamageMap.putAll(NewAPI.getHashMap("leggings", config1, i, "reboundDamage"));
        reboundDamageMap.putAll(NewAPI.getHashMap("boots", config1, i, "reboundDamage"));
        HashMap<String, Integer> experienceMap = new HashMap();
        experienceMap.putAll(NewAPI.getHashMap("arms", config1, i, "experience"));
        experienceMap.putAll(NewAPI.getHashMap("helmet", config1, i, "experience"));
        experienceMap.putAll(NewAPI.getHashMap("chestplate", config1, i, "experience"));
        experienceMap.putAll(NewAPI.getHashMap("leggings", config1, i, "experience"));
        experienceMap.putAll(NewAPI.getHashMap("boots", config1, i, "experience"));
        List<HashMap<String, Double>> list = new ArrayList();
        Iterator var9 = NewCustomCuiLian.variables.iterator();

        while(var9.hasNext()) {
            Variable v = (Variable)var9.next();
            HashMap<String, Double> map = new HashMap();
            String name = v.name;
            map.putAll(NewAPI.getHashMap("arms", config1, i, name));
            map.putAll(NewAPI.getHashMap("helmet", config1, i, name));
            map.putAll(NewAPI.getHashMap("chestplate", config1, i, name));
            map.putAll(NewAPI.getHashMap("leggings", config1, i, name));
            map.putAll(NewAPI.getHashMap("boots", config1, i, name));
            list.add(map);
        }

        return new Attribute(damageMap, bloodSuckMap, jumpMap, defenseMap, reboundDamageMap, experienceMap, list);
    }

    public static void addTypeToItem(Material m, String ss, Plugin p) {
        String s = m.name();
        YamlConfiguration config = YamlConfiguration.loadConfiguration(new File(p.getDataFolder(), "Item.yml"));
        List<String> list = config.getStringList(ss);
        if (!list.contains(s)) {
            list.add(s);
            config.set(ss, list);
            NewCustomCuiLian.customCuilianManager.ItemList.add(m);
            readCuiLianItem(p);
            NewCustomCuiLian.reloadRecipe();

            try {
                config.save(new File(p.getDataFolder(), "Item.yml"));
            } catch (IOException var7) {
            }
        }

    }

    public static void readVariables(Plugin p) {
        NewCustomCuiLian.variables.clear();
        File file1 = new File(p.getDataFolder(), "variables.yml");
        YamlConfiguration config1 = YamlConfiguration.loadConfiguration(file1);
        if (!file1.exists()) {
            p.saveResource("variables.yml", true);
            readVariables(p);
        } else {
            Iterator var3 = config1.getStringList("variables").iterator();

            while(var3.hasNext()) {
                String s = (String)var3.next();
                NewCustomCuiLian.variables.add(new Variable(s, new ArrayList()));
            }

        }
    }
}
